<template>

	<u-navbar title="友情链接" bgColor="#3F7233" :titleStyle="{ color: '#FFF', fontSize: '36rpx' }" placeholder :safeAreaInsetTop="false">
		<template #left>
			<view></view>
		</template>
	</u-navbar>
	<view class="xp24-32">
	
<!-- 		<view class="search xflex-x-between">
			
			<view class="xflex1 xflex-x">
				<input class="search-iput xflex1" v-model="keyword" type="text" placeholder="" />
				<text class="uni-icon"  @click="clearIcon">&#xe434;</text>
			</view>
			<view class="search-btn" @click="search()">
				搜索
			</view>
		</view> -->
		
		<searcha @search="search"  :left-show="false" placeholder="请输入品牌名称"/>

		<view class="xp24 xbs" v-if="nmpshow == 1">
			<view class="xfz28 xfw600 xc3">
				小程序
			</view>

			<view class="xmt32" style="display: grid;grid-template-columns: 1fr 1fr 1fr">
				<view class="xflex-y-center" @click="tonmp(item)" v-for="(item,index) in mnp" :key="index">
					<image style="width: 128rpx;height: 128rpx;"
						:src="item.image" mode=""></image>
					<view class="xflex-x xfz24 xfw500 xc90" style="text-align: left;height: 60rpx;padding: 24px 0;align-items: flex-start;">
						{{item.name}}
					</view>
				</view>
			</view>
		</view>

		<view class="xp24 xbs" v-if="hallshow == 1">
			<view class="xfz28 xfw600 xc3">
				展厅定位链接
			</view>

			<view class="" style="display: grid;grid-template-columns: 1fr 1fr 1fr">

				<view class="xflex-y-center" @click="tourl(item)" v-for="(item,index) in showhall" :key="index">
					<image style="width: 128rpx;height: 128rpx;"
						:src="item.image" mode=""></image>
					<view class="xflex-x xfz24 xfw500 xc90 xp24" style="text-align: left;height: 60rpx;padding: 24px 0;align-items: flex-start;">
						{{item.name}}
					</view>
				</view>

			</view>
		</view>

		<view class="xp24 xbs" v-if="ckShow == 1">
			<view class="xfz28 xfw600 xc3">
				仓库定位链接
			</view>

			<view class="" style="display: grid;grid-template-columns: 1fr 1fr 1fr">

				<view class="xflex-y-center" @click="tourl(item)" v-for="(item,index) in warehouse" :key="index">
					<image style="width: 128rpx;height: 128rpx;"
						:src="item.image" mode=""></image>
					<view class="xflex-x xfz24 xfw500 xc90 xp24" style="text-align: left;height: 60rpx;padding: 24px 0;align-items: flex-start;">
						{{item.name}}
					</view>
				</view>

			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from "vue";
	import {
		link,
		site,
		accesslists
	} from "@/network/home.js"
		import searcha from '../index/components/search.vue';
	let keyword = ref('')
	let mnp = ref([])
	let showhall = ref([])
	let warehouse = ref([])

	let nmpshow = ref(0)
	let hallshow = ref(0)
	let ckShow = ref(0)


	accesslists().then(res => {
		nmpshow.value = res.data.link_mnp
		hallshow.value = res.data.link_showhall
		ckShow.value = res.data.link_warehouse
	})

	// site().then(res=>{
	// 	console.log(res);
	// 	if(res.data.mnp_link == 0 && res.data.hall_house == 0){
	// 		uni.reLaunch({
	// 			url:"/pages/mine/program"
	// 		})
	// 	}
	// 	if(res.data.mnp_link == 1) {
	// 		nmpshow.value = true
	// 	}

	// 	if(res.data.hall_house == 1) {
	// 		hallshow.value = true
	// 	}
	// })

	const search = (e) => {
		keyword.value = e
		console.log("ee");
		getlink()
	}

	const getlink = () => {
		link({
			keyword: keyword.value
		}).then(res => {
			console.log(res);
			mnp.value = res.data.mnp
			showhall.value = res.data.showhall
			warehouse.value = res.data.warehouse
		})
	}

	//跳转小程序
	const tonmp = (data) => {
		wx.navigateToMiniProgram({
			shortLink: data.link,
			//develop开发版；trial体验版；release正式版
			envVersion: 'release',
			success(res) {
				// 打开成功
				console.log("跳转小程序成功！", res);
			}
		})
	}

	// 位置
	const tourl = (data) => {
		uni.openLocation({
			latitude: Number(data.lat),
			longitude: Number(data.lng)
		})
	}

	getlink()
</script>

<style lang="scss" scoped>
	.search {
		// width: 690rpx;
		// height: 68rpx;
		background: #EEEEEE;
		border-radius: 34rpx;
		padding: 0 10rpx 20rpx 28rpx;
		box-sizing: border-box;

		&-icon {
			width: 40rpx;
			height: 40rpx;
		}

		&-iput {
			font-size: 32rpx;
			font-weight: 500;
			color: #AAAAAA;
		}

		&-btn {
			width: 104rpx;
			height: 68rpx;
			background: #3F7233;
			border-radius: 24rpx;
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			text-align: center;
			line-height: 68rpx;
		}
	}
</style>